﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SummerTraining.OO
{
    public class Person
    {
        public Person()
        {
            Console.WriteLine("构造一个人");
        }

        public Person(int height, DateTime dateOfBirth) : this()
        {
            this.height = height;
            this.dateOfBirth = dateOfBirth;
            Console.WriteLine("构造一个人，身高：" + height);
        }

        private DateTime dateOfBirth;

        private int height;

        public int Height
        {
            set
            {
                height = value;
            }
            get
            {
                return height;
            }
        }

        public DateTime DateOfBirth
        {
            set
            {
                if (dateOfBirth.CompareTo(DateTime.Now) > 0)
                {
                    dateOfBirth = DateTime.Now;

                }
                else
                {
                    dateOfBirth = value;
                }
            }
            get
            {
                if (dateOfBirth == null)
                    return DateTime.Now;
                return dateOfBirth;
            }
        }

        public int Age
        {
            get
            {
                return DateTime.Now.Year - dateOfBirth.Year;
            }
        }

        public virtual void Eat()
        {

            Console.WriteLine("消耗了10近大米");
        }

        public void Eat(string food)
        {
            Console.WriteLine("吃了" + food);
        }

        public void Eat(int weight)
        {
            Console.WriteLine("消耗了" + weight + "近大米(int)");
        }

        public void Eat(long weight)
        {
            Console.WriteLine("消耗了" + weight + "近大米(long)");
        }

        public void Eat(string food, int weight)
        {
        }

        public void Eat(int weight, string food)
        {
        }

        public void Walk()
        {
        }

    }

    public class Student : Person
    {
        public Student() : base(16, DateTime.Now)
        {

        }

        public override void Eat()
        {
            Console.WriteLine("非常优雅的吃饭");
        }

        public void Study()
        {
        }

        public void Come()
        {
        }
    }

    //单例
    public class Boss : Person
    {
        private Boss()
        {

        }

        private static Boss instance = new Boss();


        public static Boss GetBoss()
        {
            return instance;
        }
    }

    public interface IPrinter
    {
        void Print(string content);
    }

    public class HPPrinter : IPrinter
    {

        public void Print(string content)
        {
            Console.WriteLine(content);
        }

    }


    public class Rect : IComparable
    {
        public Rect(int length, int width)
        {
            this.length = length;
            this.width = width;
        }

        private int length;
        private int width;

        public int Length
        {
            get
            {
                return length;
            }
            set
            { 
                length = value; 
            }

        }

        public int Width
        {
            get
            {
                return width;
            }
            set
            {
                width = value;
            }
        }

        public int Area
        {
            get
            {
                return length * width;
            }
        }

        public override string ToString()
        {
            return "length:" + length + ",width:" + width + ",area:" + Area;
        }


        #region IComparable Members

        public int CompareTo(object obj)
        {
            Rect r = (Rect)obj;
            if(Area > r.Area)
            {
                return -1;
            }
            else if (Area == r.Area)
            {
                return 0;
            }
            else
            {
                return 1;
            }
        }

        #endregion
    }

    class Class
    {
        private string[] students = {"a","b","c","d" };

        public string GetName(int index)
        {
            return students[index];
        }

        public void SetName(int index, string value)
        {
            students[index] = value;
        }

        public string this[int index]
        {
            get
            {
                return students[index];
            }
            set
            {
                students[index] = value;
            }
        }

        public int this[string chineseValue]
        {
            get
            {

                return 1;
            }
        }

    }

    public enum Gender
    {
        Male, Female
    }

    public delegate void Print(string value);

    public class Demo
    {
        public string name;
        public void Something()
        {
            p(name);
        }

        public Print p;
    }
}
